﻿unit SmOrderMstDAL;

interface

uses
  FastMM4,
  FastMove,
  System.SysUtils,
  System.Classes,
  System.Types,
  Winapi.Windows,
  Data.DB,
  Data.Win.ADODB,
  Datasnap.DBClient,
  Datasnap.Provider,
  {$IFDEF UNICODE}
  AnsiStrings,
  {$ENDIF }
  QBParcel,
  DllSpread,
  Generics.Collections,
  DateUtils,
  QJson,
  UserConnection,
  DBAccessor,
  DllPlugin,
  StrUtils,
  SK0001Comm,
  SmOrderMstModel;

type
  TSmOrderMstDAL = class(TObject)
  private
    function GenerateInsertSQLs(const iItem:TSmOrderMst; const iSQLs:TStrings; out oError:string):Boolean;
    function GenerateUpdateSQLs(const iItem:TSmOrderMst; const iSQLs:TStrings; out oError:string):Boolean;
    function GenerateDeleteSQLs(const iItem:TSmOrderMst; const iSQLs:TStrings; out oError:string):Boolean;
  protected
    fDBConn:TADOConnection;
    fDBID:string;
  public
    constructor Create(const iDBConn:TADOConnection; const iDBID:string);overload;
    destructor Destroy;override;
    
    function GetCDSModel(var iCDS:TClientDataSet; const iLoadMode:eDBLoadMode; out oError:string):Boolean;
    
    function LoadByCondition(const iItem:TSmOrderMst; const iCondition:string; const iLoadMode:eDBLoadMode; out oError:string):Boolean;overload;
    function LoadByCondition(const iItems:TSmOrderMstList; const iCondition:string; const iLoadMode:eDBLoadMode; out oError:string; const dOrderBy:string=''):Boolean;overload;
    function LoadByPageQuery(const iItems:TSmOrderMstList; const iPageNo:Integer; const iPageSize:Integer; const iCondition,iOrderBy:string; const iLoadMode:eDBLoadMode; out oTotalCount:Integer; out oError:string):Boolean;
  
    function InsertToDB(const iItem:TSmOrderMst; out oError:string):Boolean;overload;
    function InsertToDB(const iItems:TSmOrderMstList; out oError:string):Boolean;overload;
    function GetInsertSQLs(const iItem:TSmOrderMst; const iSQLs:TStrings; out oError:string):Boolean;overload;
    function GetInsertSQLs(const iItems:TSmOrderMstList; const iSQLs:TStrings; out oError:string):Boolean;overload;
    
    function UpdateToDB(const iItem:TSmOrderMst; out oError:string):Boolean;overload;
    function UpdateToDB(const iItems:TSmOrderMstList; out oError:string):Boolean;overload;
    function GetUpdateSQLs(const iItem:TSmOrderMst; const iSQLs:TStrings; out oError:string):Boolean;overload;
    function GetUpdateSQLs(const iItems:TSmOrderMstList; const iSQLs:TStrings; out oError:string):Boolean;overload;
    
    function DeleteToDB(const iItem:TSmOrderMst; out oError:string):Boolean;overload;
    function DeleteToDB(const iItems:TSmOrderMstList; out oError:string):Boolean;overload;
    function GetDeleteSQLs(const iItem:TSmOrderMst; const iSQLs:TStrings; out oError:string):Boolean;overload;
    function GetDeleteSQLs(const iItems:TSmOrderMstList; const iSQLs:TStrings; out oError:string):Boolean;overload;
  end;
  
implementation

constructor TSmOrderMstDAL.Create(const iDBConn:TADOConnection; const iDBID:string);
begin
  inherited Create;
  
  fDBConn:=iDBConn;
  fDBID:=iDBID;
end;

destructor TSmOrderMstDAL.Destroy;
begin
  inherited Destroy;
end;

function TSmOrderMstDAL.GenerateInsertSQLs(const iItem:TSmOrderMst; const iSQLs:TStrings; out oError:string):Boolean;
var
  SQL:string;
begin
  if iSQLs<>nil then
  begin
    SQL:=Format(string('INSERT INTO %s (%s,%s,%s,%s,%s,'+
                                     '%s,%s,%s,%s,%s,'+
                                     '%s,%s,%s,%s,%s,'+
                                     '%s,%s,%s,%s,%s,'+
                                     '%s,%s,%s,%s)'+
                                     'VALUES(''%s'',%d,''%s'',%d,''%s'','+
                                     '''%s'',''%s'',''%s'',''%s'',''%s'','+
                                     '''%s'',''%s'',%g,%d,%d,'+
                                     '''%s'',%s,''%s'',%s,''%s'','+
                                     '%s,''%s'',%s,%s);'),
                                     [TSmOrderMstModel.cTblName,

                                     TSmOrderMstModel.cOrderIdKey,TSmOrderMstModel.cOrderBillTypeKey,TSmOrderMstModel.cCustomerIdKey,TSmOrderMstModel.cOrderStatusKey,TSmOrderMstModel.cOrderRemarkKey,
                                     TSmOrderMstModel.cInvoiceTypeIdKey,TSmOrderMstModel.cPaywayIdKey,TSmOrderMstModel.cShipTypeIdKey,TSmOrderMstModel.cOrgIdKey,TSmOrderMstModel.cEmpIdKey,
                                     TSmOrderMstModel.cDeptIdKey,TSmOrderMstModel.cLinkmanIdKey,TSmOrderMstModel.cOrderAmountKey,TSmOrderMstModel.cOrderSendStatusKey,TSmOrderMstModel.cOrderSettlementStatusKey,
                                     TSmOrderMstModel.cRecordPsnKey,TSmOrderMstModel.cRecordDateKey,TSmOrderMstModel.cModifyPsnKey,TSmOrderMstModel.cModifyDateKey,TSmOrderMstModel.cApprovePsnKey,
                                     TSmOrderMstModel.cApproveDateKey,TSmOrderMstModel.cCancelPsnKey,TSmOrderMstModel.cCancelDateKey,TSmOrderMstModel.cTimeStampKey,

                                     string(iItem.OrderId),iItem.OrderBillType,string(iItem.CustomerId),iItem.OrderStatus,string(iItem.OrderRemark),
                                     string(iItem.InvoiceTypeId),string(iItem.PaywayId),string(iItem.ShipTypeId),string(iItem.OrgId),string(iItem.EmpId),
                                     string(iItem.DeptId),string(iItem.LinkmanId),iItem.OrderAmount,iItem.OrderSendStatus,iItem.OrderSettlementStatus,
                                     string(iItem.RecordPsn),IfThen(SameStr(FormatDateTime(string('yyyy-MM-dd hh:mm:ss'),iItem.RecordDate),string('1899-12-30 00:00:00')),'NULL',''''+FormatDateTime(string('yyyy-MM-dd hh:mm:ss'),iItem.RecordDate)+''''),string(iItem.ModifyPsn),IfThen(SameStr(FormatDateTime(string('yyyy-MM-dd hh:mm:ss'),iItem.ModifyDate),string('1899-12-30 00:00:00')),'NULL',''''+FormatDateTime(string('yyyy-MM-dd hh:mm:ss'),iItem.ModifyDate)+''''),string(iItem.ApprovePsn),
                                     IfThen(SameStr(FormatDateTime(string('yyyy-MM-dd hh:mm:ss'),iItem.ApproveDate),string('1899-12-30 00:00:00')),'NULL',''''+FormatDateTime(string('yyyy-MM-dd hh:mm:ss'),iItem.ApproveDate)+''''),string(iItem.CancelPsn),IfThen(SameStr(FormatDateTime(string('yyyy-MM-dd hh:mm:ss'),iItem.CancelDate),string('1899-12-30 00:00:00')),'NULL',''''+FormatDateTime(string('yyyy-MM-dd hh:mm:ss'),iItem.CancelDate)+''''),IntToStr(iItem.TimeStamp)]);;
    iSQLs.Add(SQL);
  end else begin
    oError:=Format(string('调用%s.GenerateInsertSQLs函数参数错误!错误内容:传入的SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.GenerateUpdateSQLs(const iItem:TSmOrderMst; const iSQLs:TStrings; out oError:string):Boolean;
var
  SQL:string;
begin
  if iSQLs<>nil then
  begin
    SQL:=Format(string('UPDATE %s SET %s=%d,%s=''%s'',%s=%d,%s=''%s'',%s=''%s'','+
                                     '%s=''%s'',%s=''%s'',%s=''%s'',%s=''%s'',%s=''%s'','+
                                     '%s=''%s'',%s=%g,%s=%d,%s=%d,%s=''%s'','+
                                     '%s=%s,%s=''%s'',%s=%s,%s=''%s'',%s=%s,'+
                                     '%s=''%s'',%s=%s,%s=%s '+
                                     'WHERE %s=''%s'' ;'),
                                     [TSmOrderMstModel.cTblName,

                                     TSmOrderMstModel.cOrderBillTypeKey,iItem.OrderBillType,TSmOrderMstModel.cCustomerIdKey,string(iItem.CustomerId),TSmOrderMstModel.cOrderStatusKey,iItem.OrderStatus,TSmOrderMstModel.cOrderRemarkKey,string(iItem.OrderRemark),TSmOrderMstModel.cInvoiceTypeIdKey,string(iItem.InvoiceTypeId),
                                     TSmOrderMstModel.cPaywayIdKey,string(iItem.PaywayId),TSmOrderMstModel.cShipTypeIdKey,string(iItem.ShipTypeId),TSmOrderMstModel.cOrgIdKey,string(iItem.OrgId),TSmOrderMstModel.cEmpIdKey,string(iItem.EmpId),TSmOrderMstModel.cDeptIdKey,string(iItem.DeptId),
                                     TSmOrderMstModel.cLinkmanIdKey,string(iItem.LinkmanId),TSmOrderMstModel.cOrderAmountKey,iItem.OrderAmount,TSmOrderMstModel.cOrderSendStatusKey,iItem.OrderSendStatus,TSmOrderMstModel.cOrderSettlementStatusKey,iItem.OrderSettlementStatus,TSmOrderMstModel.cRecordPsnKey,string(iItem.RecordPsn),
                                     TSmOrderMstModel.cRecordDateKey,IfThen(SameStr(FormatDateTime(string('yyyy-MM-dd hh:mm:ss'),iItem.RecordDate),string('1899-12-30 00:00:00')),'NULL',''''+FormatDateTime(string('yyyy-MM-dd hh:mm:ss'),iItem.RecordDate)+''''),TSmOrderMstModel.cModifyPsnKey,string(iItem.ModifyPsn),TSmOrderMstModel.cModifyDateKey,IfThen(SameStr(FormatDateTime(string('yyyy-MM-dd hh:mm:ss'),iItem.ModifyDate),string('1899-12-30 00:00:00')),'NULL',''''+FormatDateTime(string('yyyy-MM-dd hh:mm:ss'),iItem.ModifyDate)+''''),TSmOrderMstModel.cApprovePsnKey,string(iItem.ApprovePsn),TSmOrderMstModel.cApproveDateKey,IfThen(SameStr(FormatDateTime(string('yyyy-MM-dd hh:mm:ss'),iItem.ApproveDate),string('1899-12-30 00:00:00')),'NULL',''''+FormatDateTime(string('yyyy-MM-dd hh:mm:ss'),iItem.ApproveDate)+''''),
                                     TSmOrderMstModel.cCancelPsnKey,string(iItem.CancelPsn),TSmOrderMstModel.cCancelDateKey,IfThen(SameStr(FormatDateTime(string('yyyy-MM-dd hh:mm:ss'),iItem.CancelDate),string('1899-12-30 00:00:00')),'NULL',''''+FormatDateTime(string('yyyy-MM-dd hh:mm:ss'),iItem.CancelDate)+''''),TSmOrderMstModel.cTimeStampKey,IntToStr(iItem.TimeStamp),

                                     TSmOrderMstModel.cOrderIdKey,string(iItem.OrderId)]);;
    iSQLs.Add(SQL);
  end else begin
    oError:=Format(string('调用%s.GenerateInsertSQLs函数参数错误!错误内容:传入的SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.GenerateDeleteSQLs(const iItem:TSmOrderMst; const iSQLs:TStrings; out oError:string):Boolean;
var
  SQL:string;
begin
  if iSQLs<>nil then
  begin
    SQL:=Format(string('DELETE FROM %s WHERE %s=''%s'' ;'),
                                     [TSmOrderMstModel.cTblName,
                                     TSmOrderMstModel.cOrderIdKey,string(iItem.OrderId)]);;
    iSQLs.Add(SQL);
  end else begin
    oError:=Format(string('调用%s.GenerateInsertSQLs函数参数错误!错误内容:传入的SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.GetCDSModel(var iCDS:TClientDataSet; const iLoadMode:eDBLoadMode; out oError:string):Boolean;
var
  Condition:string;
begin
  if (iCDS<>nil) then
  begin
    Condition:='1=0';
    if not TSK0001Comm.GetCDS(fDBConn,fDBID,TSmOrderMstModel.GetQuerySQL(Condition,EmptyStr,iLoadMode),iCDS,oError) then
    begin
      oError:=Format(string('调用%s.GetCDSModel函数-->%s'),[Self.ClassName,oError]);
      Result:=False;
      Exit; 
    end;
  end else begin
    oError:=Format(string('调用%s.GetCDSModel函数错误!错误内容:传入的数据集对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.LoadByCondition(const iItem:TSmOrderMst; const iCondition:string; const iLoadMode:eDBLoadMode; out oError:string):Boolean;
var
  CDS:TClientDataSet;
begin
  if (iItem<>nil) and (not SameStr(Trim(iCondition),EmptyStr)) then
  begin
    CDS:=TClientDataSet.Create(nil);
    try
      if TSK0001Comm.GetCDS(fDBConn,fDBID,TSmOrderMstModel.GetQuerySQL(iCondition,EmptyStr,iLoadMode),CDS,oError) then
      begin
        if not iItem.LoadFromCDS(CDS,oError) then
        begin
          oError:=Format(string('调用%s.LoadByCondition单例函数-->%s'),[Self.ClassName,oError]);
          Result:=False;
          Exit;
        end;
      end else begin
        oError:=Format(string('调用%s.LoadByCondition单例函数-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit; 
      end;
    finally
      FreeAndNil(CDS);
    end;
  end else begin
    oError:=Format(string('调用%s.LoadByCondition单例函数错误!错误内容:传入的实体对象为空或者查询条件为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.LoadByCondition(const iItems:TSmOrderMstList; const iCondition:string; const iLoadMode:eDBLoadMode; out oError:string; const dOrderBy:string):Boolean;
var
  CDS:TClientDataSet;
begin
  if (iItems<>nil) then
  begin
    CDS:=TClientDataSet.Create(nil);
    try
      if TSK0001Comm.GetCDS(fDBConn,fDBID,TSmOrderMstModel.GetQuerySQL(iCondition,dOrderBy,iLoadMode),CDS,oError) then
      begin
        if not iItems.LoadFromCDS(CDS,oError) then
        begin
          oError:=Format(string('调用%s.LoadByCondition列表函数-->%s'),[Self.ClassName,oError]);
          Result:=False;
          Exit;
        end;
      end else begin
        oError:=Format(string('调用%s.LoadByCondition列表函数-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(CDS);
    end;
  end else begin
    oError:=Format(string('调用%s.LoadByCondition列表函数错误!错误内容:传入的实体列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.LoadByPageQuery(const iItems:TSmOrderMstList; const iPageNo:Integer; const iPageSize:Integer; const iCondition,iOrderBy:string; const iLoadMode:eDBLoadMode; out oTotalCount:Integer; out oError:string):Boolean;
var
  CDS,CdsCount:TClientDataSet;
begin
  if (iItems<>nil) and (iPageNo>0) and (iPageSize>0) and not SameStr(Trim(iOrderBy),EmptyStr) then
  begin
    CDS:=TClientDataSet.Create(nil);
    CdsCount:=TClientDataSet.Create(nil);
    try      
      if TSK0001Comm.GetCDS(fDBConn,fDBID,TSmOrderMstModel.GetCountSQL(iCondition,iLoadMode),CdsCount,oError) and
        TSK0001Comm.GetCDS(fDBConn,fDBID,TSmOrderMstModel.GetPageQuerySQL(iPageNo,iPageSize,iCondition,iOrderBy,iLoadMode),CDS,oError) then
      begin
        oTotalCount:=CdsCount.FieldByName('COUNT').AsInteger;
        if not iItems.LoadFromCDS(CDS,oError) then
        begin
          oTotalCount:=0;  
          oError:=Format(string('调用%s.LoadByPageQuery列表函数-->%s'),[Self.ClassName,oError]);
          Result:=False;
          Exit;
        end;
      end else begin
        oTotalCount:=0;
        oError:=Format(string('调用%s.LoadByPageQuery列表函数-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(CDS);
      FreeAndNil(CdsCount);
    end;
  end else begin
    oTotalCount:=0;
    oError:=Format(string('调用%s.LoadByPageQuery列表函数错误!错误内容:传入的实体列表对象为空或者排序参数为空或者页号、页大小非法!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.InsertToDB(const iItem:TSmOrderMst; out oError:string):Boolean;
var
  SQLs:TStrings;
begin
  if (iItem<>nil) then
  begin
    SQLs:=TStringList.Create;
    try
      if GetInsertSQLs(iItem,SQLs,oError) and TSK0001Comm.ExecuteSQLs(fDBConn,fDBID,SQLs,oError) then
      begin
  
      end else begin
        oError:=Format(string('调用%s.InsertToDB单例函数-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit;
      end;
    finally
      SQLs.Free;
    end;
  end else begin
    oError:=Format(string('调用%s.InsertToDB单例函数错误!错误内容:传入的实体对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.InsertToDB(const iItems:TSmOrderMstList; out oError:string):Boolean;
var
  SQLs:TStrings;
begin
  if (iItems<>nil) then
  begin
    SQLs:=TStringList.Create;
    try
      if GetInsertSQLs(iItems,SQLs,oError) and TSK0001Comm.ExecuteSQLs(fDBConn,fDBID,SQLs,oError) then
      begin
  
      end else begin
        oError:=Format(string('调用%s.InsertToDB列表-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit;
      end;
    finally
      SQLs.Free;
    end;
  end else begin
    oError:=Format(string('调用%s.InsertToDB列表函数错误!错误内容:传入的实体列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.GetInsertSQLs(const iItem:TSmOrderMst; const iSQLs:TStrings; out oError:string):Boolean;
begin
  if (iItem<>nil) and (iSQLs<>nil) then
  begin
    if not GenerateInsertSQLs(iItem,iSQLs,oError) then
    begin
      oError:=Format(string('调用%s.GetInsertSQLs单例函数-->%s'),[Self.ClassName,oError]);
      Result:=False;
      Exit;
    end;
  end else begin
    oError:=Format(string('调用%s.GetInsertSQLs单例函数错误!错误内容:传入的实体对象或SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.GetInsertSQLs(const iItems:TSmOrderMstList; const iSQLs:TStrings; out oError:string):Boolean;
var
  Key:string;
begin
  if (iItems<>nil) and (iSQLs<>nil) then
  begin
    for Key in iItems.SortKeys do
    begin
      if not GenerateInsertSQLs(iItems.FindByKey(Key),iSQLs,oError) then
      begin
        oError:=Format(string('调用%s.GetInsertSQLs列表函数-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit;
      end;
    end;
  end else begin
    oError:=Format(string('调用%s.GetInsertSQLs列表函数错误!错误内容:传入的实体列表对象或SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.UpdateToDB(const iItem:TSmOrderMst; out oError:string):Boolean;
var
  SQLs:TStrings;
begin
  if (iItem<>nil) then
  begin
    SQLs:=TStringList.Create;
    try
      if GetUpdateSQLs(iItem,SQLs,oError) and TSK0001Comm.ExecuteSQLs(fDBConn,fDBID,SQLs,oError) then
      begin
  
      end else begin
        oError:=Format(string('调用%s.UpdateToDB单例函数-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit;
      end;
    finally
      SQLs.Free;
    end;
  end else begin
    oError:=Format(string('调用%s.UpdateToDB单例函数错误!错误内容:传入的实体对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.UpdateToDB(const iItems:TSmOrderMstList; out oError:string):Boolean;
var
  SQLs:TStrings;
begin
  if (iItems<>nil) then
  begin
    SQLs:=TStringList.Create;
    try
      if GetUpdateSQLs(iItems,SQLs,oError) and TSK0001Comm.ExecuteSQLs(fDBConn,fDBID,SQLs,oError) then
      begin
  
      end else begin
        oError:=Format(string('调用%s.UpdateToDB列表函数-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit;
      end;
    finally
      SQLs.Free;
    end;
  end else begin
    oError:=Format(string('调用%s.UpdateToDB列表函数错误!错误内容:传入的实体列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.GetUpdateSQLs(const iItem:TSmOrderMst; const iSQLs:TStrings; out oError:string):Boolean;
begin
  if (iItem<>nil) and (iSQLs<>nil) then
  begin
    if not GenerateUpdateSQLs(iItem,iSQLs,oError) then
    begin
      oError:=Format(string('调用%s.GetUpdateSQLs单例函数-->%s'),[Self.ClassName,oError]);
      Result:=False;
      Exit;
    end;
  end else begin
    oError:=Format(string('调用%s.GetUpdateSQLs单例函数错误!错误内容:传入的实体对象或SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.GetUpdateSQLs(const iItems:TSmOrderMstList; const iSQLs:TStrings; out oError:string):Boolean;
var
  Key:string;
begin
  if (iItems<>nil) and (iSQLs<>nil) then
  begin
    for Key in iItems.SortKeys do
    begin
      if not GenerateUpdateSQLs(iItems.FindByKey(Key),iSQLs,oError) then
      begin
        oError:=Format(string('调用%s.GetUpdateSQLs列表函数-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit;
      end;
    end;
  end else begin
    oError:=Format(string('调用%s.GetUpdateSQLs列表函数错误!错误内容:传入的实体列表对象或SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.DeleteToDB(const iItem:TSmOrderMst; out oError:string):Boolean;
var
  SQLs:TStrings;
begin
  if (iItem<>nil) then
  begin
    SQLs:=TStringList.Create;
    try
      if GetDeleteSQLs(iItem,SQLs,oError) and TSK0001Comm.ExecuteSQLs(fDBConn,fDBID,SQLs,oError) then
      begin
  
      end else begin
        oError:=Format(string('调用%s.DeleteToDB单例函数-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit;
      end;
    finally
      SQLs.Free;
    end;
  end else begin
    oError:=Format(string('调用%s.DeleteToDB单例函数错误!错误内容:传入的实体对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.DeleteToDB(const iItems:TSmOrderMstList; out oError:string):Boolean;
var
  SQLs:TStrings;
begin
  if (iItems<>nil) then
  begin
    SQLs:=TStringList.Create;
    try
      if GetDeleteSQLs(iItems,SQLs,oError) and TSK0001Comm.ExecuteSQLs(fDBConn,fDBID,SQLs,oError) then
      begin
  
      end else begin
        oError:=Format(string('调用%s.DeleteToDB列表函数-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit;
      end;
    finally
      SQLs.Free;
    end;
  end else begin
    oError:=Format(string('调用%s.DeleteToDB列表函数错误!错误内容:传入的实体列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.GetDeleteSQLs(const iItem:TSmOrderMst; const iSQLs:TStrings; out oError:string):Boolean;
begin
  if (iItem<>nil) and (iSQLs<>nil) then
  begin
    if not GenerateDeleteSQLs(iItem,iSQLs,oError) then
    begin
      oError:=Format(string('调用%s.GetDeleteSQLs单例函数-->%s'),[Self.ClassName,oError]);
      Result:=False;
      Exit;
    end;
  end else begin
    oError:=Format(string('调用%s.GetDeleteSQLs单例函数错误!错误内容:传入的实体对象或SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSmOrderMstDAL.GetDeleteSQLs(const iItems:TSmOrderMstList; const iSQLs:TStrings; out oError:string):Boolean;
var
  Key:string;
begin
  if (iItems<>nil) and (iSQLs<>nil) then
  begin
    for Key in iItems.SortKeys do
    begin
      if not GenerateDeleteSQLs(iItems.FindByKey(Key),iSQLs,oError) then
      begin
        oError:=Format(string('调用%s.GetDeleteSQLs列表函数-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit;
      end;
    end;
  end else begin
    oError:=Format(string('调用%s.GetDeleteSQLs列表函数错误!错误内容:传入的实体列表对象或SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
end.
